<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改活动配置')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<style>
    .in-row{
        clear: both;
    }
    .in-row label{
        float: left;
        width: 75px;
        margin: 5px 5px 5px 5px;
        text-align:right;
    }
    .in-row span{
        float: left;
    }
    .in-row .btn-default{
        float: left;
        color: #555;
        margin-left: 10px;
        padding: 5px 5px;
        border: 1px solid #ddd;
        border-radius: 4px;
        background: transparent;
        outline: none;
        height: 30px;
        width: 100px;
    }
    .in-row div select,.in-row div input {
        float: left;
        border: 1px solid #ddd;
        border-radius: 4px;
        background: transparent;
        outline: none;
        height: 30px;
        width: 100px;
    }
    .border{
        border:1px solid #ddd;
        margin-bottom: 5px;
        padding: 10px 10px 10px 10px;
    }
</style>
<body class="white-bg" style="line-height:2">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-s-edit">
        <input name="llf_money" type="hidden" th:value="${llf_money}">
        <input name="llf_lc_money" type="hidden" th:value="${llf_lc_money}">
        <input name="fwf_money" type="hidden" th:value="${fwf_money}">
        <input name="fwf_lc_money" type="hidden" th:value="${fwf_lc_money}">
        <input name="jh_money" type="hidden" th:value="${jh_money}">
        <input name="jh_lc_money" type="hidden" th:value="${jh_lc_money}">
        <input name="db_money" type="hidden" th:value="${db_money}">
        <input name="db_lc_money" type="hidden" th:value="${db_lc_money}">
        <div class="tab-content">
            <div class="in-row" >
                <h4 class="form-header h4">政策信息</h4>
                <div>
                    <label style="width: 160px;">活动：</label>
                    <input type="text" readonly style="width: 160px;background-color: #ffffff;border: none;"  class="form-control" name="actId"  th:value="${actId}">
                </div>
                <div>
                    <label style="width: 160px;">代理商编号：</label>
                    <input  type="text" readonly style="width: 160px;background-color: #ffffff;border: none;" class="form-control" name="agentNum"  th:value="${agentNum}">
                </div>
            </div>
            <div class="row">
                <div class="in-row">
                    <div class="in-row">
                        <h4 class="form-header h4">基础留存</h4>
                        <div>
                            <label style="width: 130px;">流量费返现(元)：</label>
                            <input type="text"  readonly style="width: 160px;background-color: #ffffff;border: none;" class="form-control" name="llf_money" th:value="${llf_money}">
                        </div>
                        <div>
                            <label style="width: 100px;" th:text="${'留存金额(' + llf_lc_money + '元)'}">：</label>
                            <input type="number" min="0" style="width: 160px;" class="form-control" name="my_llf_lc_money" th:value="${my_llf_lc_money}">
                        </div>
                    </div>
                    <div class="in-row">
                        <div>
                            <label style="width: 130px;" >服务费返现(元)：</label>
                            <input type="text" readonly style="width: 160px;background-color: #ffffff;border: none;" class="form-control" name="fwf_money" th:value="${fwf_money}">
                        </div>
                        <div>
                            <label style="width: 100px;" th:text="${'留存金额(' + fwf_lc_money + '元)'}">：</label>
                            <input type="number" min="0" style="width: 160px;" class="form-control" name="my_fwf_lc_money" th:value="${my_fwf_lc_money}">
                        </div>
                    </div>
                    <div class="in-row">
                        <div>
                            <label style="width: 130px;">激活返现(元)：</label>
                            <input type="text" readonly style="width: 160px;background-color: #ffffff;border: none;" class="form-control" name="jh_money" th:value="${jh_money}">
                        </div>
                        <div>
                            <label style="width: 100px;" th:text="${'留存金额(' + jh_lc_money + '元)'}">：</label>
                            <input type="number" min="0" style="width: 160px;" class="form-control" name="my_jh_lc_money" th:value="${my_jh_lc_money}">
                        </div>
                    </div>
                    <div class="in-row">
                        <div>
                            <label style="width: 130px;">达标返现(元)：</label>
                            <input type="text" readonly style="width: 160px;background-color: #ffffff;border: none;" class="form-control" name="db_money" th:value="${db_money}">
                        </div>
                        <div>
                            <label style="width: 100px;" th:text="${'留存金额(' + db_lc_money + '元)'}">：</label>
                            <input type="number" min="0" style="width: 160px;" class="form-control" name="my_db_lc_money" th:value="${my_db_lc_money}">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row" id="stageArray">
                <div class="in-row">
                    <h4 class="form-header h4">阶段留存</h4>
                    <div class="in-row"  th:each="list:${stageList}">
                        <div>
                            <label style="width: 100px;">阶段：</label>
                            <input type="text" readonly style="width: 50px;background-color: #ffffff;border: none;" class="form-control" name="stage" th:value="${list?.stage - 2}">
                        </div>
                        <div>
                            <label style="width: 100px;">返现金额：</label>
                            <input type="text" readonly style="width: 160px;background-color: #ffffff;border: none;" class="form-control" name="jd_money" th:value="${list?.jd_money}">
                        </div>
                        <div style="display: none">
                            <label>：</label>
                            <input type="hidden" name="jd_lc_money"  th:value="${list?.jd_lc_money}">
                        </div>
                        <div>
                            <label style="width: 100px;" th:text="${'留存金额(' + list?.jd_lc_money + '元)'}">留存金额：</label>
                            <input type="number" min="0" style="width: 160px;" class="form-control" name="my_jd_lc_money" th:value="${list?.my_jd_lc_money}">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "agentInfo/agentActActive";

    $("#form-s-edit").validate({
        rules: {
            agentNum: {
                required: true,
            },
            createDate: {
                required: true,
            },
            messages:{
                agentNum: {
                    required: '请输入代理商编号',
                },
                createDate: {
                    required: '请选择开始日期',
                },
            },
        }
    });


    function submitHandler() {
        if ($.validate.form()) {
            //阶段规则
            let jsonArray = [];
            let data = new Object();
            $("#stageArray input").each(function (index) {
                if ($.common.isEmpty(this.value)){
                   $.modal.msgError("阶段留存金额不可为空");
                    event.returnValue=false;
                    return;
               }
                data[this.name] = this.value;
                if ((index + 1) % 4 == 0){
                    jsonArray.push(data);
                    data = new Object();
                }
            });
            let reqData = {
                "agentNum":$("[name='agentNum']").val(),
                "actId":$("[name='actId']").val(),
                "llf_money":$("[name='llf_money']").val(),
                "llf_lc_money":$("[name='llf_lc_money']").val(),
                "my_llf_lc_money":$("[name='my_llf_lc_money']").val(),
                "fwf_money":$("[name='fwf_money']").val(),
                "fwf_lc_money":$("[name='fwf_lc_money']").val(),
                "my_fwf_lc_money":$("[name='my_fwf_lc_money']").val(),
                "jh_money":$("[name='jh_money']").val(),
                "jh_lc_money":$("[name='jh_lc_money']").val(),
                "my_jh_lc_money":$("[name='my_jh_lc_money']").val(),
                "db_money":$("[name='db_money']").val(),
                "db_lc_money":$("[name='db_lc_money']").val(),
                "my_db_lc_money":$("[name='my_db_lc_money']").val(),
                "stageList":JSON.stringify(jsonArray)};
                $.operate.saveJson(prefix + "/saveLc", JSON.stringify(reqData));
        }
    }

    function deleteRow(e){
        $(e).parents(".in-row").remove();
    }

    /**
     * 新增阶梯节点
     */
    function dbInsert(e){
        var html =
            "<div class=\"in-row\" >\n" +
            "                    <div>\n" +
            "                        <label style=\"width: 100px;\">开始天数：</label>\n" +
            "                        <input type=\"text\" style=\"width: 160px;\" class=\"form-control\" name=\"beginDate\" th:value=\"${act?.beginDate}\">\n" +
            "                    </div>\n" +
            "                    <div>\n" +
            "                        <label style=\"width: 100px;\">结束天数：</label>\n" +
            "                        <input type=\"text\" style=\"width: 160px;\" class=\"form-control\" name=\"endDate\" th:value=\"${act?.endDate}\">\n" +
            "                    </div>\n" +
            "                    <div>\n" +
            "                        <label style=\"width: 100px;\">分润比例：</label>\n" +
            "                        <input type=\"text\" style=\"width: 160px;\" class=\"form-control\" name=\"ratio\" th:value=\"${act?.ratio}\">\n" +
            "                    </div>\n" +
            "                        <button type=\"button\" class=\"btn btn-default\" onclick=\"deleteRow(this)\">删除阶段</button>" +
            "</div>";
        $(e).parents(".row").append(html);
    }

    $("input[name='createDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });


</script>
</body>
</html>
